import fs from 'fs'
import { join, resolve } from 'path'

// 找到存在 .git 文件夹的目录
export function gitDir(path: string = resolve()): string {
  if (!path) return ''
  const gitPath = join(path, '.git')
  if (fs.existsSync(gitPath)) {
    return path
  }

  const nextPath = resolve(path, '../')
  if (nextPath === path) return ''
  return gitDir(nextPath)
}
